<?php
namespace app\index\controller;


class Article extends MyController
{
    //文章列表页
    public function index()
    {
        $default = db('info_category')->min('cat_id');
        $cid = input('cid',$default);
        $catename = db('info_category')->where('cat_id',$cid)->value('cat_title');
        $current = input('page',1);
        $limit = 10;
        $start = ($current-1)*$limit;
        $info = db('information')
            ->where('cat_id',$cid)
            ->order('info_id','DESC')
            ->limit($start,$limit)
            ->paginate($limit);
        $this->assign([
            'catename'=>$catename,
            'info'=>$info,
        ]);
        return view();
    }
    //文章详情页
    public function detail(){
        $iid = input('iid');
        $article = db('information')
            ->where('info_id',$iid)
            ->find();
        //上下篇id
        $previd = db('information')
            ->where('info_id','>',$iid)
            ->min('info_id');
        $nextid = db('information')
            ->where('info_id','<',$iid)
            ->max('info_id');
        $this->assign([
            'article'=>$article,
            'previd'=>$previd,
            'nextid'=>$nextid,
        ]);
        return view();
    }
}
